package net.yiny.scrummer.ui.storyboard

import groovy.swing.SwingBuilder
import javax.swing.JFrame
import javax.swing.border.EmptyBorder
import net.miginfocom.swing.MigLayout

public class CardBuilder {

    def nameField, idField, descriptionField

    def initialise() {
        def layout = new MigLayout('flowy', '[2.5in!]')
        EmptyBorder emptyBorder = new EmptyBorder(0, 0, 0, 0)
        def swing = new SwingBuilder()
        swing.panel(layout: layout) {
            idField = textField(name: 'id', columns: 5, enabled: false, editable: false,
                    border: emptyBorder)
            nameField = textField(name: 'name', columns: 15, enabled: false, editable: false,
                    border: emptyBorder)
            scrollPane(constraints: 'growx') {
                descriptionField = textArea(name: 'description', lineWrap: true,
                        rows: 6, enabled: false, editable: false)
            }
        }
    }

    void setName(name) {
        nameField.text = name
    }

    void setId(id) {
        idField.text = id
    }

    void setDescription(description) {
        descriptionField.text = description
    }

    static void main(args) {
        def builder = new CardBuilder()
        def frame = new JFrame(title: 'Test')
        frame.with {
            defaultCloseOperation = EXIT_ON_CLOSE
            contentPane.add builder.initialise()
            builder.name = 'Test Name'
            builder.id = '#204'
            builder.description = 'Test Description longer\n' * 5
            pack()
            visible = true
        }
    }
}
